package com.yowasa.xiuxian.engine.hone.mental;


import com.google.common.collect.Lists;
import com.yowasa.xiuxian.annoations.Mental;
import com.yowasa.xiuxian.constant.XiuxianConstants;
import com.yowasa.xiuxian.engine.hone.MentalInterface;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.bo.user.UserBattle;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.entity.enums.StageEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.UserTagHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mental(name = "九转轮回功")
public class JiuZhuanLunHui implements MentalInterface {
    public static final Logger logger = LoggerFactory.getLogger(JiuZhuanLunHui.class);

    @Autowired
    private UserTagHelper userTagHelper;
    @Override
    public ElementEnum getElement() {
        return null;
    }

    @Override
    public void limit(UserBO user) {
        int value = userTagHelper.getValue(user.getUserId(), XiuxianConstants.TAG_FEISHENG);
        if (value == 0) {
            throw new HandlerException("修习九转轮回功需要先飞升");
        }
    }

    @Override
    public String limitDesc() {
        return "需要先飞升";
    }

    @Override
    public String desc() {
        return "轮回者的专属心法，轮回次数越多，修炼速度越慢，但突破后的属性也越强，轮回者会拥有额外的寿命";
    }

    @Override
    public List<String> bsList() {
        return Lists.newArrayList("六道轮转");
    }

    @Override
    public String breakUp(UserBO user) {
        int value = userTagHelper.getValue(user.getUserId(), XiuxianConstants.TAG_FEISHENG);
        logger.info("获取当前飞升tag：----  {}",value);
        value = value >= 9 ? 9:value;
        double v = 1 + 0.2 * value;
        user.getUserConfig().setLife(user.getUserConfig().getLife() + 30 * value);
        UserBattle upBattle = getBaseUp(user);
        upBattle.setHp((int) ((upBattle.getHp() + 5) * v));
        upBattle.setChp(upBattle.getHp());
        upBattle.setMp((int) ((upBattle.getMp() + 5) * v));
        upBattle.setCmp(upBattle.getMp());
        upBattle.setAtk((int) ((upBattle.getAtk() + 2) * v));
        upBattle.setSpell((int) ((upBattle.getSpell() + 2) * v));
        upBattle.setSpd((int) ((upBattle.getSpd()+2) * v));
        upBattle.setDef((int) ((upBattle.getDef()+2) * v));
        upBattle.setRes((int) ((upBattle.getRes() + 2) * v));
        upBattle.setImm((int) (upBattle.getImm() * v));
        buildNewUpBattle(user, upBattle);
        return upBattle.getUpDesc();
    }

    @Override
    public List<String> specialList() {
        return Lists.newArrayList("轮回体");
    }

    //预估修炼时间
    public int getExpect(UserBO user) {
        int value = userTagHelper.getValue(user.getUserId(), XiuxianConstants.TAG_FEISHENG);
        Integer code = user.getStage();
        StageEnum level = StageEnum.getById(code);
        int need = level.getNeed();
        int i = 15 * (value + 1);
        int und = i >= 120 ? 110 : i;

        return ((100 - user.getLevel()) * need) * 200 / (30 * (120 - und));
    }

    //修炼获取经验
    public int getExp(UserBO user, int days) {
        int value = userTagHelper.getValue(user.getUserId(), XiuxianConstants.TAG_FEISHENG);
        int i = 15 * (value + 1);
        int und = i >= 120 ? 110 : i;
        return (30 * (120 - und) * days) / 200;
    }

}
